/*
 * @Author: your name
 * @Date: 2021-12-23 19:49:56
 * @LastEditTime: 2021-12-25 09:50:12
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \day12 ts 路由 月考\my-app\src\store\index.tsx
 */
import {createStore,applyMiddleware} from "redux"
import thunk from "redux-thunk"
import logger from "redux-logger"
import {IState,allAction,GETLIST,CHANGESTORE} from "./store.d"

let reducer=(state:IState={list:[],newList:[]},action:allAction)=>{
    switch (action.type) {
        case GETLIST:
            return {
                ...state,
                list:[...state.list,...action.payload],
                newList:[...state.list,...action.payload]
            }
        case CHANGESTORE:
            let {info,index}=action
            let newsList=state.newList.filter((item:any)=>item[info]===index)
            return {
                ...state,
                list:[...newsList]
            }
        default:
            return {
                ...state
            }
    }
}

let store=createStore(reducer,applyMiddleware(thunk,logger))

export default store